package io.renren.modules.dangan.service.impl;

import cn.hutool.core.util.NumberUtil;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.commons.dynamic.datasource.annotation.DataSource;
import io.renren.modules.dangan.dao.DaOaWsDao;
import io.renren.modules.dangan.entity.DaOaWsEntity;
import io.renren.modules.dangan.service.DaJnmlbService;
import io.renren.modules.dangan.service.DaOaWsService;
import io.renren.modules.dangan.service.DaServerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("daOaWsService")
@DataSource("dlmis")
@Slf4j
public class DaOaWsServiceImpl extends ServiceImpl<DaOaWsDao, DaOaWsEntity> implements DaOaWsService {


    @Value("${oaWsServerXh:7}")
    private Integer oaWsServerXh;

    @CreateCache(name="ljCache",localExpire=1800,cacheType= CacheType.LOCAL)
    private Cache<String,String> ljCache;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String swbh=params.getOrDefault("swbh","").toString();
        String wh=params.getOrDefault("wh","").toString();
        String nd=params.getOrDefault("nd","").toString();
        String bt=params.getOrDefault("bt","").toString();
        String vrecid=params.getOrDefault("vrecid","").toString();
        log.info(params.toString());
        IPage<DaOaWsEntity> page = this.page(
                new Query<DaOaWsEntity>().getPage(params),
                new QueryWrapper<DaOaWsEntity>()
                        .eq(StringUtils.isNotBlank(vrecid),"vrecid",vrecid)
                        .like(StringUtils.isNotBlank(swbh),"vswbh",swbh.trim())
                .like(StringUtils.isNotBlank(wh),"vlwbh",wh.trim())
                .like(StringUtils.isNotBlank(nd),"nd",nd.trim())
                .like(StringUtils.isNotBlank(bt),"vlwbt",bt.trim())
        );
        return new PageUtils(page);
    }
}
